// components/footChoose.js
import Dialog from '@vant/weapp/dialog/dialog';

Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    visible: false,
    currentDish: null,
    selectedSpec: '',
    flavor:[]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    showDialog(dish) {
      if(! dish.hasOwnProperty('flavors')) return
      if(dish.flavors===null) return
      
      // console.log(dish.flavors.value);
      const flavors=dish.flavors.value.replace("[", '').replace("]", "").replace(/"/g,"").split(",");

      this.setData({
        flavor:flavors,
        visible: true,
        currentDish: dish,
        selectedSpec: flavors.length ? 0: ''
      });
    },
    handleSpecChange(e) {
      this.setData({
        selectedSpec: e.detail
      })
    },
    handleConfirm() {
      const {
        currentDish,
        selectedSpec,
        flavor
      } = this.data;
      this.triggerEvent("specConfirm", {
        dish: currentDish,
        selectedSpec: selectedSpec,
        flavor:flavor[selectedSpec]
      });
      this.setData({
        visible: false
      });
    },
    handleCancel() {
      this.setData({
        visible: false
      })
    }
  }
})